﻿using System;
using System.Collections;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SportsStore.Domain.Entities;
using SportsStore.Domain.Concrete;


namespace SportsStore.UnitTests
{
    [TestClass]
    public class UnitTest4
    {
        
        public void TestMethod1()
        {

        }

        [TestMethod]
        public void CanGetAllProducts()
        {
            EFProductRepository repository = new EFProductRepository();
            IEnumerable<Product> products = repository.Products;
            Assert.IsTrue(products.Count()==17);
        }

        public void CanAddProduct()
        {
            EFProductRepository repository = new EFProductRepository();
            Product product = new Product { };
        }

        [TestMethod]
        public void CanGetAllImage()
        {
            EFImageRepository repository = new EFImageRepository();
            IEnumerable<Image> images = repository.Images;
            Assert.IsTrue(images.Count()==18);
        }

        #region Category Entity Test
        [TestMethod]
        public void CanAddCategory()
        {
            EFCategoryRepository repository = new EFCategoryRepository();
            Category category = new Category {Description = "this is a test category", Id = 0, Ranking = 9};
            repository.SaveCategory(category);

        }

        [TestMethod]
        public void CanEditCategory()
        {
            EFCategoryRepository repository = new EFCategoryRepository();
            Category modifyinyCategory = new Category {Id = 9, Name = "EditName", Ranking = 10, Description = "EditDescription"};
            repository.SaveCategory(modifyinyCategory);
            Category modifiedCategory = repository.Categories.FirstOrDefault(c => c.Id == 9);
            Assert.AreEqual("EditName",modifiedCategory.Name);
            Assert.AreEqual("EditDescription",modifiedCategory.Description);
            Assert.AreEqual(10,modifiedCategory.Ranking);
        }

        [TestMethod]
        public void CanDeleteCategory()
        {
            EFCategoryRepository repository = new EFCategoryRepository();
            Category deletingCategory = repository.Categories.FirstOrDefault(c => c.Id == 9);
            repository.DeleteCategory(deletingCategory);
            Category deletedCategory = repository.Categories.FirstOrDefault(c => c.Id == 9);
            Assert.IsNull(deletedCategory);
        }
        #endregion


        
    }
}
